using System.Xml;

using ZJGIS.ADF.Node;

namespace Shine.ManageUser
{
    /// <summary>
    /// 作用：空间数据节点
    /// 作者：叶茂
    /// 修改日期：2009-06-19
    /// </summary>
    public class GeoDataNode : ResourceNode
    {     
        private IDataNode dataNode;
        private string typeName;
        private WORKSPACETYPE workspacetype;
        private bool canedit = true;
        private IPropertySet pPropertySet = null;
        public IPropertySet PropertySet
        {
            get
            {
                return pPropertySet;
            }
            set
            {
                pPropertySet = value;
            }
        }
        public override XmlElement ToXmlNode(XmlDocument xmlDoc)
        {
            XmlElement xmlEle = xmlDoc.CreateElement("FeatureClass");
            xmlEle.SetAttribute("name", name);
            xmlEle.SetAttribute("value", dataNode.Name);
            xmlEle.SetAttribute("enable", Enable.ToString());
            xmlEle.SetAttribute("workspacetype", ((int)(dataNode.WorkspaceType)).ToString());
           
            object names=null;
            object values=null;
            string strPro = "";
            if (dataNode.PropertySet != null)
            {
                dataNode.PropertySet.GetAllProperties(out names, out values);

                string[] strNames = (string[])names;
                System.Array strValues = (System.Array)values;
                for (int i = 0; i < strNames.Length; i++)
                {
                    if (strNames[i].ToUpper() == "PASSWORD")
                    {
                        string strPassword = "";
                        if (strValues.GetValue(i).GetType() == typeof(string))
                        {
                            strPassword = strValues.GetValue(i).ToString();
                        }
                        else
                        {
                            byte[] bytes = (byte[])strValues.GetValue(i);
                           
                            for (int j = 0; j < bytes.Length; j++)
                            {
                                strPassword += bytes[j].ToString() + "|";
                            }
                            strPassword = strPassword.Remove(strPassword.Length - 1, 1);
                        }
                        strPro += strNames[i] + "=" + strPassword + ";";
                    }
                    else
                        strPro += strNames[i] + "=" + strValues.GetValue(i).ToString() + ";";
                }
            }
            PropertySet = dataNode.PropertySet;
            xmlEle.SetAttribute("dbconnection", strPro);
            xmlEle.SetAttribute("typename", dataNode.GetType().AssemblyQualifiedName);
            xmlEle.SetAttribute("canedit", canedit.ToString());
            foreach (IResourceNode node in childnodes)
            {
                XmlElement xmlElep = node.ToXmlNode(xmlDoc);
                if (xmlElep != null)
                {
                    xmlEle.AppendChild(xmlElep);
                }
            }
            return xmlEle; 
        }
        public IDataNode DataNode
        {
            get { return dataNode; }
            set { dataNode = value; }
        }
        public string TypeName
        {
            get { return typeName; }
            set { typeName = value; }
        }
        public WORKSPACETYPE WorkspaceType
        {
            get
            {
                return workspacetype;
            }
            set
            {
                workspacetype = value;
            }
        }
        public bool Canedit
        {
            get { return canedit; }
            set { canedit = value; }
        }
    }
}